﻿using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.IO;

using System.Text.RegularExpressions;



namespace EventTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Temperature g = new Temperature();
            g.BoilEvent += Airconditioning.alert;
            g.BoilEvent += Heating.alert;
            while (true)
            {
                g.Release();
                Console.WriteLine();
            }
        }

    }

    class Temperature
    {
        private double temperature;
        public delegate void BoilHandler(double temperature);
        public event BoilHandler BoilEvent;
        public void Release()
        {

            Console.WriteLine("请输入当前温度：");
            temperature = double.Parse(Console.ReadLine());
            if (BoilEvent != null)
            {
                Console.WriteLine("当前时间为{0}，此刻的温度为{1}°", DateTime.Now.ToString(), temperature);
                BoilEvent(temperature);

            }

        }

        public event EventHandler<ThresholdReachedEventArgs> ThresholdReached;
    }
    public class Airconditioning
    {
        public static void alert(double temperature)
        {
            if (temperature > 30)
                Console.WriteLine("当前温度超过30°空调启动");
            else if (temperature < 28)
                Console.WriteLine("当前温度低于28°空调关闭");
            else
                Console.WriteLine("当前温度正常");
        }
    }
    public class Heating
    {
        public static void alert(double temperature)
        {
            if (temperature > 20)
                Console.WriteLine("当前温度超过20°暖气启动");
            else if (temperature < 10)
                Console.WriteLine("当前温度低于10°暖气关闭");
            else
                Console.WriteLine("当前温度正常，无需暖气");
        }
    }
    public class ThresholdReachedEventArgs : EventArgs
    {
        public int Threshold { get; set; }
        public DateTime TimeReached { get; set; }
    }
}